package com.kxmall.web.controller.huishou;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.kxmall.common.annotation.RepeatSubmit;
import com.kxmall.common.annotation.Log;
import com.kxmall.common.core.controller.BaseController;
import com.kxmall.common.core.domain.PageQuery;
import com.kxmall.common.core.domain.R;
import com.kxmall.common.core.validate.AddGroup;
import com.kxmall.common.core.validate.EditGroup;
import com.kxmall.common.enums.BusinessType;
import com.kxmall.common.utils.poi.ExcelUtil;
import com.kxmall.huishou.domain.vo.HsUserTaskVo;
import com.kxmall.huishou.domain.bo.HsUserTaskBo;
import com.kxmall.huishou.service.IHsUserTaskService;
import com.kxmall.common.core.page.TableDataInfo;

/**
 * 用户任务信息
 *
 * @author kxmall
 * @date 2023-11-23
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/huishou/userTask")
public class HsUserTaskController extends BaseController {

    private final IHsUserTaskService iHsUserTaskService;

    /**
     * 查询用户任务信息列表
     */
    @SaCheckPermission("huishou:userTask:list")
    @GetMapping("/list")
    public TableDataInfo<HsUserTaskVo> list(HsUserTaskBo bo, PageQuery pageQuery) {
        return iHsUserTaskService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出用户任务信息列表
     */
    @SaCheckPermission("huishou:userTask:export")
    @Log(title = "用户任务信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HsUserTaskBo bo, HttpServletResponse response) {
        List<HsUserTaskVo> list = iHsUserTaskService.queryList(bo);
        ExcelUtil.exportExcel(list, "用户任务信息", HsUserTaskVo.class, response);
    }

    /**
     * 获取用户任务信息详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("huishou:userTask:query")
    @GetMapping("/{id}")
    public R<HsUserTaskVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(iHsUserTaskService.queryById(id));
    }

    /**
     * 新增用户任务信息
     */
    @SaCheckPermission("huishou:userTask:add")
    @Log(title = "用户任务信息", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody HsUserTaskBo bo) {
        return toAjax(iHsUserTaskService.insertByBo(bo));
    }

    /**
     * 修改用户任务信息
     */
    @SaCheckPermission("huishou:userTask:edit")
    @Log(title = "用户任务信息", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody HsUserTaskBo bo) {
        return toAjax(iHsUserTaskService.updateByBo(bo));
    }

    /**
     * 删除用户任务信息
     *
     * @param ids 主键串
     */
    @SaCheckPermission("huishou:userTask:remove")
    @Log(title = "用户任务信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(iHsUserTaskService.deleteWithValidByIds(Arrays.asList(ids), true));
    }
}
